package com.example.wm.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.wm.common.Result;
import com.example.wm.common.ResultData;
import com.example.wm.entity.Complaints;

import com.example.wm.mapper.ComplaintsMapper;
import com.example.wm.service.CompliantsService;
import com.example.wm.service.DibanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/complaints")
//举报
public class ComplaintsController {
    @Resource
    private CompliantsService compliantsService;
    @Resource
    private ComplaintsMapper complaintsMapper;
    @Transactional
    @PostMapping("/save")
    public Result saveAddress(@RequestBody Complaints complaints) {
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
        Date date = new Date(System.currentTimeMillis());
        String time = formatter.format(date);
            complaints.setTime(time);
            compliantsService.save(complaints);
            return null;
        }

    @Transactional
    @CrossOrigin
    @PostMapping("/findAll")
    public  Result complaintsfindAll(){


        // 创建查询构造器
        LambdaQueryWrapper<Complaints> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.last("order by time desc");

        // 调用mapper查询数据
        List<Complaints> list = complaintsMapper.selectList(queryWrapper);
        return ResultData.success("操作成功",list);
    }

}
